package com.test;

import com.domain.Student;

import java.util.ArrayList;

public class ArrayTest2 {
    /*
        需求：创建方法，从集合中筛选出年龄低于18的学生对象存入新集合
     */
    public static void main(String[] args) {
        ArrayList<Student> list=new ArrayList<>();
        list.add(new Student("张三",25));
        list.add(new Student("李四",15));
        list.add(new Student("王五",12));

        ArrayList<Student> newList=filtrate(list);

        for (int i = 0; i < newList.size(); i++) {
            System.out.println(newList.get(i).getName()+"--"+newList.get(i).getAge());
        }
    }

    private static ArrayList<Student> filtrate(ArrayList<Student> list) {
        ArrayList<Student> newList=new ArrayList<Student>();
        for (int i = 0; i < list.size(); i++) {
            Student stu=list.get(i);
            if(stu.getAge()<18){
                newList.add(stu);
            }
        }
        return newList;
    }
}
